home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nejlepší hry
/
Nejlepsi hry.iso
/
hry
/
sea of chaos
/
sea_install.msi
/
_15C39AAA7726369D39812BD40F01CF6A
/
_6C5F263CF14F488884592093FD1BEBC3
< prev
next >
Wrap
Text File
|
2005-02-17
|
2KB
|
101 lines
//submerged object vertex shader:
//ripples the vertices of things underwater
//2 directional lights and ambient light also applied
//must be used with submerged.psh
//Luke Lenhart
//(C)2004-2005 Digipen Institute of Technology
//NOTE: only vertices with a z value < -2 will be affected by this effect
//combined view,projection transform
float4x4 matViewProj;
//world transform
float4x4 matWorld;
//rotational transform from world
float4x4 matWorldRotation;
//2 directional lights
float4 l1Direction;
float4 l1Color;
float4 l2Direction;
float4 l2Color;
//ambient light
float4 lAmbient;
//alpha modifier for mesh
float alphaMod;
//camera position in world space
float4 cameraPos;
//current time (in seconds) since whenever
float curTime;
//multiplier for how much underwater wavery effect gets applied
float waveMod;
//shader input
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Normal : NORMAL;
float2 Tex0 : TEXCOORD0;
};
//shader output
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
float2 Tex0 : TEXCOORD0;
};
//shader code
VS_OUTPUT VShader(VS_INPUT In)
{
VS_OUTPUT Out;
//calc colors from directional lights
float4 norm=mul(matWorldRotation,-In.Normal);
float4 l1Contrib=dot(norm,l1Direction)*l1Color;
l1Contrib=saturate(l1Contrib);
float4 l2Contrib=dot(norm,l2Direction)*l2Color;
l2Contrib=saturate(l2Contrib);
Out.Color=l1Contrib + l2Contrib + lAmbient;
//calc transformed position and copy texture coord
Out.Tex0=In.Tex0;
float4 worldPos=mul(matWorld,In.Pos);
//do ripple effect if z is less than -2
if (worldPos.z<-2.0f) //underwater
{
//use 1/distance from camera is a base offset distance
float invCamDist=1.0f/distance(cameraPos,worldPos);
float2 theta=In.Pos.xy+curTime;
theta.y+=3.14;
worldPos.xy+=waveMod*sqrt(invCamDist)*worldPos.z*2.5f*sin(theta);
//less alpha with less z
Out.Color.a=1.0f+worldPos.z/9.0f;
}
else //above water
{
Out.Color.a=1.0f;
}
//do view/project transform
Out.Pos=mul(matViewProj,worldPos);
//modify alpha
Out.Color.a*=alphaMod;
//spit out the results
return Out;
}